<script lang="ts" setup name="XtxCheckbox">

const { modelValue } = defineProps<{
  modelValue: boolean
}>()

const emit = defineEmits<{
  (e: 'update:modelValue', val: boolean): void
}>()
const hClick = () => {
  // 通知父组件，取反
  emit("update:modelValue", !modelValue)
}
</script>

<template>
  <div class="xtx-checkbox">
    <!-- 选中时，要显示的图标 -->
    <i @click="hClick" v-if="modelValue" class="iconfont icon-checked"></i>
    <!-- 未选中时，要显示的图标 -->
    <i @click="hClick" v-else class="iconfont icon-unchecked"></i>

    <!-- 文字 -->
    <span><slot /></span>
  </div>
</template>

<style scoped lang="less">
.xtx-checkbox {
  display: inline-block;
  margin-right: 2px;
  .icon-checked {
    color: @xtxColor;
    ~ span {
      color: @xtxColor;
    }
  }
  i {
    position: relative;
    top: 1px;
  }
  span {
    margin-left: 2px;
  }
}
</style>